﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using QLTH_DTO;

namespace QLTH_DATASSECC
{
   public class clsMonHocDA: ConnectionData.clsKetNoi
    {
       String _sql;

       public DataTable DanhSachMonHoc()
       {
           _sql = "select MAMH, TENMON, cast (0 as bit) as STT from MONHOC";
           return Load_DataTable(_sql);
       }

       public int ThemMonHoc(clsMonHocDTO mhdto)
       {
           int nameparam = 5;
           String[] name = new String[nameparam];
           Object[] values = new Object[nameparam];
           name[0] = "@Mamh"; values[0] = mhdto.Mamh;
           name[1] = "@Tenmh"; values[1] = mhdto.Tenmh;
           name[2] = "@Matcm"; values[2] = mhdto.Tcm.Matcm;
           name[3] = "@Hesp"; values[3] = mhdto.Heso;
           name[4] = "@Sotiet"; values[4] = mhdto.Sotiet;
           _sql = "INSERT INTO MONHOC VALUES (@Mamh,@Matcm,@Tenmh,@Sotiet,@Heso)";
           return Nonquery(_sql, name, values, nameparam);
       }

       public int CapNhatMonHoc(clsMonHocDTO mhdto)
       {
           int nameparam = 5;
           String[] name = new String[nameparam];
           Object[] values = new Object[nameparam];
           name[0] = "@Mamh"; values[0] = mhdto.Mamh;
           name[1] = "@Tenmh"; values[1] = mhdto.Tenmh;
           name[2] = "@Matcm"; values[2] = mhdto.Tcm.Matcm;
           name[3] = "@Hesp"; values[3] = mhdto.Heso;
           name[4] = "@Sotiet"; values[4] = mhdto.Sotiet;
           _sql = "UPDATE MONHOC SET TENMON = @Tenmh, MATCM = @Matcm, SOTIET = @Sotiet, HESO = @Heso where MAMH = @Mamh";
           return Nonquery(_sql, name, values, nameparam);
       }

       public int XoaMonHoc(clsMonHocDTO mhdto)
       {
           int nameparam = 1;
           String[] name = new String[nameparam];
           Object[] values = new Object[nameparam];
           name[0] = "@Mamh"; values[0] = mhdto.Mamh;
           _sql = "DELETE MONHOC WHERE MAMH = @Mamh";
           return Nonquery(_sql, name, values, nameparam);
           
       }

       public string ma_cuoi()
        {
            _sql = "SELECT TOP 1 MAMH FROM MONHOC ORDER BY MAMH DESC";
            return laymacuoi(_sql);
           
       }
    }
}
